<style>
#ol_list_topick li{margin:3px; border-bottom: 1px dashed gray;}
#ol_list_topick li input{vertical-align:middle;}
</style>
<div class="q_box">
<h3><?php echo t::out($B['vote']->v('Name'));?></h3>
<blockquote><?php echo t::out($B['vote']->v('Description'));?></blockquote>
<div style="font-size: 9.5pt;margin-bottom: -10px;">
	<span style="float:right;">
		<b><?php echo t::out($B['creator']);?></b>发起于<?php echo date("Y-m-d",$B['vote']->v('CreateTime'));?>，
		投票日期:<?php echo date("Y-m-d",$B['vote']->v('BeginTime'));?>至<?php echo date("Y-m-d",$B['vote']->v('BeginTime')+3600*24*($B['vote']->v('DayLast')-1));?>
	</span>
	<b style="color:red;">
		<i class="icon-star"></i>
		<?php if($B['vote']->v('VoteType')==0):?>
		单选型投票，您只能投给其中一项。
		<?php elseif($B['vote']->v('VoteType')==1):?>
		多选型投票，您必须选择其中<?php echo $B['vote']->v('PickLimit');?>项。
		<?php elseif($B['vote']->v('VoteType')==2):?>
		多选型投票，您至多可以投给其中<?php echo $B['vote']->v('PickLimit');?>项。
		<?php endif;?>
	</b>	
</div>
<hr/>
<?php if($B['access']['access'])://能否投票,不能投就显示投票结果?>
<ol id="ol_list_topick">
	<?php 
	$options = json_decode($B['vote']->v('Options'),true);
	foreach($options as $k=>$v):?>
	<li>
		<label>
			<input type="<?php echo $B['vote']->v('VoteType')?"checkbox":"radio";?>" name="pick_option" value="<?php echo $k;?>" />
			<?php echo t::out($v);?>
		</label> 
	</li>
	<?php endforeach;?>
</ol>
<hr />
<div class="control-group">
	<div class="controls">
		<button type="submit" id="vote_btn" class="btn btn-primary">
			提交
		</button>
		<button type="reset" class="btn">
			重置
		</button>
	</div>
</div>

<?php if($B['vote']->v('Uid')==$_SESSION['uid'])://发布者可直接查看投票结果?>
<hr/><h3>投票结果</h3><hr/>
<div class="alert alert-info">
	<span style="float:right;">共有<?php echo $B['vote']->v('VoteNum');?>人次参与了投票。</span>
	<div class="clearfix"></div>
</div>
<ol>
	<?php 
	$options = json_decode($B['vote']->v('Options'),true);
	$result = json_decode($B['vote']->v('Result'),true);
	foreach($options as $k=>$v):?>
	<li>
		<span style="float:right;"><?php echo ($result[$k]?$result[$k]:"0")."/".$B['vote']->v('VoteNum');?></span>
		<?php echo t::out($v);?>
		<div class="progress">			
			<div class="bar" style="width: <?php echo $B['vote']->v('VoteNum')==0?0:(($result[$k]?$result[$k]:0)*100/($B['vote']->v('VoteNum')));?>%;"></div>
		</div>
	</li>
	<?php endforeach;?>
</ol>
<?php endif;?>

<?php else:?>
<div class="alert alert-info">
	<span style="float:right;">共有<?php echo $B['vote']->v('VoteNum');?>人次参与了投票。</span>
	您不能对此投票，因为<?php echo $B['access']['reason'];?><br />	
</div>
<ol>
	<?php 
	$options = json_decode($B['vote']->v('Options'),true);
	$result = json_decode($B['vote']->v('Result'),true);
	foreach($options as $k=>$v):?>
	<li>
		<span style="float:right;"><?php echo ($result[$k]?$result[$k]:"0")."/".$B['vote']->v('VoteNum');?></span>
		<?php echo t::out($v);?>
		<div class="progress">			
			<div class="bar" style="width: <?php echo $B['vote']->v('VoteNum')==0?0:(($result[$k]?$result[$k]:0)*100/($B['vote']->v('VoteNum')));?>%;"></div>
		</div>
	</li>
	<?php endforeach;?>
</ol>
<?php endif;?>
</div>
<?php if($B['access']['access'])://能投票时设置限制js?>
<script>
$('#ol_list_topick :radio,:checkbox').click(function(){
	if($(this).is(':checked') && $('#ol_list_topick :checked').length > <?php echo $B['vote']->v('PickLimit');?>){
		art.dialog.alert("本投票限制选择<?php echo $B['vote']->v('PickLimit');?>项!");
		$(this).attr("checked",false);
	}
});
$("#vote_btn").click(function(){
	if($('#ol_list_topick :checked').length > <?php echo $B['vote']->v('PickLimit');?>){
		art.dialog.alert("本投票限制选择<?php echo $B['vote']->v('PickLimit');?>项!您选择了"+$('#ol_list_topick :checked').length+"项.");
		return false;
	}
	if($('#ol_list_topick :checked').length == 0){
		art.dialog.alert("您尚未选择任何选项!");
		return false;
	}
	var picked = new Array();
	$('#ol_list_topick :checked').each(function(){
		picked.push($(this).val());
	});
	$.post(
		'<?php echo BASE_URL;?>/?c=vote&a=vote&rand='+Math.random(),
		{'id':<?php echo $B['vote']->v('Id');?>,'picked':picked},
		function(data){
			if(data.succeed == 1){
				art.dialog.tips("投票成功!谢谢您的参与!请稍后...",2);
				setTimeout(function(){window.location.reload();},1500);
			}else{
				art.dialog.alert(data.msg);
			}
		},
		'json'
	);
	return false;
});
</script>
<?php endif;?>